package com.tgy.binarysearch;

import java.util.Objects;

/**
 * @Author: tgy
 * @Date: 2020-11-17 16:19
 */
public class BSLastEqualValue {

    public int binarySearch(Integer[] nums, int value) {

        if (Objects.isNull(nums) || nums.length == 0) {

            return -1;
        }

        int left = 0,right = nums.length,mid;


        while (left + 1 < right) {

            mid = (left + right) >> 1;

            System.out.println(nums[mid]);
            if (value >= nums[mid]) {

                left = mid;
            }else {

                right = mid;
            }
        }

        return nums[left] == value ? left:-1;
    }
}
